package com.ruoyi.web.controller.school;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.school.domain.PacClass;
import com.ruoyi.school.domain.PacClass;
import com.ruoyi.school.domain.PacCollege;
import com.ruoyi.school.service.PacAuditRecordsService;
import com.ruoyi.school.service.PacClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/*
 * @Author Lin
 * @Description 班级相关接口
 * @Date 2025/5/25
 */
@Api("班级相关接口")
@RestController
@RequestMapping("/school/class")
public class PacClassController extends BaseController {
    @Resource
    private PacClassService pacClassService;

    /**
     * 绑定班级
     *
     * @param pacClass
     * @return
     */
    @ApiOperation("绑定班级")
    @Log(title = "绑定班级", businessType = BusinessType.INSERT)
    @PostMapping("/bind")
    public AjaxResult bind(@RequestBody PacClass pacClass) {
        pacClassService.bindClass(pacClass);
        return success();
    }

    /**
     * 查询所有未绑定的班级
     */
    @GetMapping("/noBindAll")
    public AjaxResult all(PacClass pacClass) {
        List<PacClass> pacClassList = pacClassService.getNoBindAllByName(pacClass);
        return success(pacClassList);
    }

    /**
     * 班级列表查询（关联学院和院系）
     */
    @GetMapping("/list")
    public TableDataInfo list(PacClass pacClass) {  // 实体类改为班级实体
        startPage();
        List<PacClass> list = pacClassService.getList(pacClass);  // 调用班级服务的列表方法
        return getDataTable(list);
    }

    /**
     * 班级详情查询（含学院和院系信息）
     */
    @GetMapping("/details")
    public AjaxResult details(PacClass pacClass) {  // 实体类改为班级实体
        PacClass details = pacClassService.getDetails(pacClass);  // 调用班级服务的详情方法
        return success(details);
    }

    /**
     * 新增班级（需关联学院和院系）
     */
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PacClass pacClass) {  // 实体类改为班级实体
        boolean add = pacClassService.add(pacClass);  // 调用班级服务的新增方法
        return success(add);
    }

    /**
     * 修改班级（含学院和院系关联调整）
     */
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult update(@RequestBody PacClass pacClass) {  // 实体类改为班级实体
        boolean update = pacClassService.edit(pacClass);  // 调用班级服务的修改方法
        return success(update);
    }

    /**
     * 删除班级（需确认学院和院系关联关系）
     */
    @Log(title = "班级", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult delete(PacClass pacClass) {  // 实体类改为班级实体
        boolean delete = pacClassService.delete(pacClass);  // 调用班级服务的删除方法
        return success(delete);
    }

    @ApiOperation("所有班级")
    @GetMapping("/all1")
    public AjaxResult all1(PacClass pacClass) {
        List<PacClass> list = pacClassService.getAllList(pacClass);
        return success(list);
    }

}
